/**
 * Created by YY on 7/20/2016.
 */
  angular.module('teacher')
    .config(function ($stateProvider) {
      $stateProvider
        .state('teacher', {
          url: '/teacher',
          templateUrl: 'app/teacher/teacher.html',
          controller: 'teacherCtrl'
        })
    })
    .controller('teacherHeaderCtrl', function ($log, $scope, teacherFactory) {
      teacherFactory.getCourseList(function (data) {
        $log.debug(data.data.data);
        $scope.names = data.data.data;
      });
      $scope.selectedName = teacherFactory.getCurrentCourse();
      $scope.$watch('selectedName', function (newValue) {
        $log.info(newValue);
        teacherFactory.setCurrentCourse(newValue);
      });
    })
    .controller('teacherCtrl', function ($scope, $mdSidenav, $location, checkCredit, $log, teacherFactory) {
      var selectedItem;
      if (!checkCredit(2)) {
        $location.path('/login');
      }
      teacherFactory.getName(function (name) {
        $scope.name = name;
      });
      $scope.items = [
        {
          sref:'teacher.qa',
          content:'问答',
          icon:'help'
        }, {
          sref:'teacher.class',
          content:'班级',
          icon:'class'
        },{
          sref:'teacher.pool',
          content: '题库',
          icon: 'folder'
        },{
          sref:'teacher.sign',
          content:'签到',
          icon:'fingerprint'
        },{
          sref:'teacher.doc',
          content:'课件',
          icon:'description'
        },{
          sref:'teacher.person',
          content:'个人',
          icon:'person'
        }
      ];
      $scope.toggleList = function () {
        $mdSidenav('left').toggle();
      };
    });